package com.flurry.sdk;

import io.fabric.sdk.android.services.common.AbstractSpiCall;
import io.fabric.sdk.android.services.network.HttpRequest;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.util.List;

public class ku extends mb {
    static final String e = ku.class.getSimpleName();
    private kt A = new kt(this);
    private int a;
    private int b;
    private final kd<String, String> c = new kd<>();
    /* access modifiers changed from: private */
    public HttpURLConnection d;
    public String f;
    public a g;
    public int h = AbstractSpiCall.DEFAULT_TIMEOUT;
    public int i = 15000;
    public boolean j = true;
    public c k;
    public boolean l;
    long m = -1;
    public long n = -1;
    public Exception o;
    public int p = -1;
    public final kd<String, String> q = new kd<>();
    public boolean r;
    public int s = 25000;
    public boolean t;
    private boolean x;
    private boolean y;
    private final Object z = new Object();

    public interface c {
        void a(ku kuVar);

        void a(ku kuVar, InputStream inputStream) throws Exception;

        void a(OutputStream outputStream) throws Exception;
    }

    public static class b implements c {
        public final void a(OutputStream outputStream) throws Exception {
        }

        public void a(ku kuVar, InputStream inputStream) throws Exception {
        }

        public void a(ku kuVar) {
        }
    }

    public enum a {
        kUnknown,
        kGet,
        kPost,
        kPut,
        kDelete,
        kHead;

        public final String toString() {
            switch (this) {
                case kPost:
                    return HttpRequest.METHOD_POST;
                case kPut:
                    return HttpRequest.METHOD_PUT;
                case kDelete:
                    return HttpRequest.METHOD_DELETE;
                case kHead:
                    return HttpRequest.METHOD_HEAD;
                case kGet:
                    return HttpRequest.METHOD_GET;
                default:
                    return null;
            }
        }
    }

    public final void a(String str, String str2) {
        this.c.a(str, str2);
    }

    public final boolean b() {
        boolean z2;
        synchronized (this.z) {
            z2 = this.y;
        }
        return z2;
    }

    public final boolean c() {
        return !e() && d();
    }

    public final boolean d() {
        return this.p >= 200 && this.p < 400 && !this.t;
    }

    public final boolean e() {
        return this.o != null;
    }

    public final List<String> a(String str) {
        return this.q.a(str);
    }

    public final void f() {
        km.a(3, e, "Cancelling http request: " + this.f);
        synchronized (this.z) {
            this.y = true;
        }
        if (!this.x) {
            this.x = true;
            if (this.d != null) {
                new Thread() {
                    public final void run() {
                        try {
                            if (ku.this.d != null) {
                                ku.this.d.disconnect();
                            }
                        } catch (Throwable th) {
                        }
                    }
                }.start();
            }
        }
    }

    public void a() {
        try {
            if (this.f != null) {
                if (!jr.a().b) {
                    km.a(3, e, "Network not available, aborting http request: " + this.f);
                    this.A.a();
                    h();
                    return;
                }
                if (this.g == null || a.kUnknown.equals(this.g)) {
                    this.g = a.kGet;
                }
                i();
                km.a(4, e, "HTTP status: " + this.p + " for url: " + this.f);
                this.A.a();
                h();
            }
        } catch (Exception e2) {
            km.a(4, e, "HTTP status: " + this.p + " for url: " + this.f);
            km.a(3, e, "Exception during http request: " + this.f, e2);
            this.b = this.d.getReadTimeout();
            this.a = this.d.getConnectTimeout();
            this.o = e2;
        } finally {
            this.A.a();
            h();
        }
    }

    public final void g() {
        f();
    }

    /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r2v0, resolved type: java.io.InputStream} */
    /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r2v1, resolved type: java.io.InputStream} */
    /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r2v2, resolved type: java.io.InputStream} */
    /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r2v3, resolved type: java.io.InputStream} */
    /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r2v4, resolved type: java.io.InputStream} */
    /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r3v4, resolved type: java.io.OutputStream} */
    /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r2v5, resolved type: java.io.InputStream} */
    /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r2v6, resolved type: java.io.InputStream} */
    /* JADX WARNING: Multi-variable type inference failed */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private void i() throws Exception {
        /*
            r8 = this;
            r2 = 0
            boolean r0 = r8.y
            if (r0 == 0) goto L_0x0006
        L_0x0005:
            return
        L_0x0006:
            java.lang.String r0 = r8.f
            java.lang.String r0 = com.flurry.sdk.ly.a((java.lang.String) r0)
            r8.f = r0
            java.net.URL r0 = new java.net.URL
            java.lang.String r1 = r8.f
            r0.<init>(r1)
            java.net.URLConnection r0 = r0.openConnection()     // Catch:{ all -> 0x0078 }
            java.net.HttpURLConnection r0 = (java.net.HttpURLConnection) r0     // Catch:{ all -> 0x0078 }
            r8.d = r0     // Catch:{ all -> 0x0078 }
            java.net.HttpURLConnection r0 = r8.d     // Catch:{ all -> 0x0078 }
            int r1 = r8.h     // Catch:{ all -> 0x0078 }
            r0.setConnectTimeout(r1)     // Catch:{ all -> 0x0078 }
            java.net.HttpURLConnection r0 = r8.d     // Catch:{ all -> 0x0078 }
            int r1 = r8.i     // Catch:{ all -> 0x0078 }
            r0.setReadTimeout(r1)     // Catch:{ all -> 0x0078 }
            java.net.HttpURLConnection r0 = r8.d     // Catch:{ all -> 0x0078 }
            com.flurry.sdk.ku$a r1 = r8.g     // Catch:{ all -> 0x0078 }
            java.lang.String r1 = r1.toString()     // Catch:{ all -> 0x0078 }
            r0.setRequestMethod(r1)     // Catch:{ all -> 0x0078 }
            java.net.HttpURLConnection r0 = r8.d     // Catch:{ all -> 0x0078 }
            boolean r1 = r8.j     // Catch:{ all -> 0x0078 }
            r0.setInstanceFollowRedirects(r1)     // Catch:{ all -> 0x0078 }
            java.net.HttpURLConnection r0 = r8.d     // Catch:{ all -> 0x0078 }
            com.flurry.sdk.ku$a r1 = com.flurry.sdk.ku.a.kPost     // Catch:{ all -> 0x0078 }
            com.flurry.sdk.ku$a r3 = r8.g     // Catch:{ all -> 0x0078 }
            boolean r1 = r1.equals(r3)     // Catch:{ all -> 0x0078 }
            r0.setDoOutput(r1)     // Catch:{ all -> 0x0078 }
            java.net.HttpURLConnection r0 = r8.d     // Catch:{ all -> 0x0078 }
            r1 = 1
            r0.setDoInput(r1)     // Catch:{ all -> 0x0078 }
            com.flurry.sdk.kd<java.lang.String, java.lang.String> r0 = r8.c     // Catch:{ all -> 0x0078 }
            java.util.Collection r0 = r0.b()     // Catch:{ all -> 0x0078 }
            java.util.Iterator r3 = r0.iterator()     // Catch:{ all -> 0x0078 }
        L_0x005a:
            boolean r0 = r3.hasNext()     // Catch:{ all -> 0x0078 }
            if (r0 == 0) goto L_0x007d
            java.lang.Object r0 = r3.next()     // Catch:{ all -> 0x0078 }
            java.util.Map$Entry r0 = (java.util.Map.Entry) r0     // Catch:{ all -> 0x0078 }
            java.net.HttpURLConnection r4 = r8.d     // Catch:{ all -> 0x0078 }
            java.lang.Object r1 = r0.getKey()     // Catch:{ all -> 0x0078 }
            java.lang.String r1 = (java.lang.String) r1     // Catch:{ all -> 0x0078 }
            java.lang.Object r0 = r0.getValue()     // Catch:{ all -> 0x0078 }
            java.lang.String r0 = (java.lang.String) r0     // Catch:{ all -> 0x0078 }
            r4.addRequestProperty(r1, r0)     // Catch:{ all -> 0x0078 }
            goto L_0x005a
        L_0x0078:
            r0 = move-exception
            r8.j()
            throw r0
        L_0x007d:
            com.flurry.sdk.ku$a r0 = com.flurry.sdk.ku.a.kGet     // Catch:{ all -> 0x0078 }
            com.flurry.sdk.ku$a r1 = r8.g     // Catch:{ all -> 0x0078 }
            boolean r0 = r0.equals(r1)     // Catch:{ all -> 0x0078 }
            if (r0 != 0) goto L_0x009a
            com.flurry.sdk.ku$a r0 = com.flurry.sdk.ku.a.kPost     // Catch:{ all -> 0x0078 }
            com.flurry.sdk.ku$a r1 = r8.g     // Catch:{ all -> 0x0078 }
            boolean r0 = r0.equals(r1)     // Catch:{ all -> 0x0078 }
            if (r0 != 0) goto L_0x009a
            java.net.HttpURLConnection r0 = r8.d     // Catch:{ all -> 0x0078 }
            java.lang.String r1 = "Accept-Encoding"
            java.lang.String r3 = ""
            r0.setRequestProperty(r1, r3)     // Catch:{ all -> 0x0078 }
        L_0x009a:
            boolean r0 = r8.y     // Catch:{ all -> 0x0078 }
            if (r0 == 0) goto L_0x00a3
            r8.j()
            goto L_0x0005
        L_0x00a3:
            com.flurry.sdk.ku$a r0 = com.flurry.sdk.ku.a.kPost     // Catch:{ all -> 0x0078 }
            com.flurry.sdk.ku$a r1 = r8.g     // Catch:{ all -> 0x0078 }
            boolean r0 = r0.equals(r1)     // Catch:{ all -> 0x0078 }
            if (r0 == 0) goto L_0x00cd
            java.net.HttpURLConnection r0 = r8.d     // Catch:{ all -> 0x013f }
            java.io.OutputStream r3 = r0.getOutputStream()     // Catch:{ all -> 0x013f }
            java.io.BufferedOutputStream r1 = new java.io.BufferedOutputStream     // Catch:{ all -> 0x01a1 }
            r1.<init>(r3)     // Catch:{ all -> 0x01a1 }
            com.flurry.sdk.ku$c r0 = r8.k     // Catch:{ all -> 0x01a5 }
            if (r0 == 0) goto L_0x00c7
            boolean r0 = r8.b()     // Catch:{ all -> 0x01a5 }
            if (r0 != 0) goto L_0x00c7
            com.flurry.sdk.ku$c r0 = r8.k     // Catch:{ all -> 0x01a5 }
            r0.a((java.io.OutputStream) r1)     // Catch:{ all -> 0x01a5 }
        L_0x00c7:
            com.flurry.sdk.ly.a((java.io.Closeable) r1)     // Catch:{ all -> 0x0078 }
            com.flurry.sdk.ly.a((java.io.Closeable) r3)     // Catch:{ all -> 0x0078 }
        L_0x00cd:
            boolean r0 = r8.l     // Catch:{ all -> 0x0078 }
            if (r0 == 0) goto L_0x00d7
            long r0 = java.lang.System.currentTimeMillis()     // Catch:{ all -> 0x0078 }
            r8.m = r0     // Catch:{ all -> 0x0078 }
        L_0x00d7:
            boolean r0 = r8.r     // Catch:{ all -> 0x0078 }
            if (r0 == 0) goto L_0x00e3
            com.flurry.sdk.kt r0 = r8.A     // Catch:{ all -> 0x0078 }
            int r1 = r8.s     // Catch:{ all -> 0x0078 }
            long r4 = (long) r1     // Catch:{ all -> 0x0078 }
            r0.a((long) r4)     // Catch:{ all -> 0x0078 }
        L_0x00e3:
            java.net.HttpURLConnection r0 = r8.d     // Catch:{ all -> 0x0078 }
            int r0 = r0.getResponseCode()     // Catch:{ all -> 0x0078 }
            r8.p = r0     // Catch:{ all -> 0x0078 }
            boolean r0 = r8.l     // Catch:{ all -> 0x0078 }
            if (r0 == 0) goto L_0x0100
            long r0 = r8.m     // Catch:{ all -> 0x0078 }
            r4 = -1
            int r0 = (r0 > r4 ? 1 : (r0 == r4 ? 0 : -1))
            if (r0 == 0) goto L_0x0100
            long r0 = java.lang.System.currentTimeMillis()     // Catch:{ all -> 0x0078 }
            long r4 = r8.m     // Catch:{ all -> 0x0078 }
            long r0 = r0 - r4
            r8.n = r0     // Catch:{ all -> 0x0078 }
        L_0x0100:
            com.flurry.sdk.kt r0 = r8.A     // Catch:{ all -> 0x0078 }
            r0.a()     // Catch:{ all -> 0x0078 }
            java.net.HttpURLConnection r0 = r8.d     // Catch:{ all -> 0x0078 }
            java.util.Map r0 = r0.getHeaderFields()     // Catch:{ all -> 0x0078 }
            java.util.Set r0 = r0.entrySet()     // Catch:{ all -> 0x0078 }
            java.util.Iterator r3 = r0.iterator()     // Catch:{ all -> 0x0078 }
        L_0x0113:
            boolean r0 = r3.hasNext()     // Catch:{ all -> 0x0078 }
            if (r0 == 0) goto L_0x0148
            java.lang.Object r0 = r3.next()     // Catch:{ all -> 0x0078 }
            java.util.Map$Entry r0 = (java.util.Map.Entry) r0     // Catch:{ all -> 0x0078 }
            java.lang.Object r1 = r0.getValue()     // Catch:{ all -> 0x0078 }
            java.util.List r1 = (java.util.List) r1     // Catch:{ all -> 0x0078 }
            java.util.Iterator r4 = r1.iterator()     // Catch:{ all -> 0x0078 }
        L_0x0129:
            boolean r1 = r4.hasNext()     // Catch:{ all -> 0x0078 }
            if (r1 == 0) goto L_0x0113
            java.lang.Object r1 = r4.next()     // Catch:{ all -> 0x0078 }
            java.lang.String r1 = (java.lang.String) r1     // Catch:{ all -> 0x0078 }
            com.flurry.sdk.kd<java.lang.String, java.lang.String> r5 = r8.q     // Catch:{ all -> 0x0078 }
            java.lang.Object r6 = r0.getKey()     // Catch:{ all -> 0x0078 }
            r5.a(r6, r1)     // Catch:{ all -> 0x0078 }
            goto L_0x0129
        L_0x013f:
            r0 = move-exception
            r1 = r2
        L_0x0141:
            com.flurry.sdk.ly.a((java.io.Closeable) r1)     // Catch:{ all -> 0x0078 }
            com.flurry.sdk.ly.a((java.io.Closeable) r2)     // Catch:{ all -> 0x0078 }
            throw r0     // Catch:{ all -> 0x0078 }
        L_0x0148:
            com.flurry.sdk.ku$a r0 = com.flurry.sdk.ku.a.kGet     // Catch:{ all -> 0x0078 }
            com.flurry.sdk.ku$a r1 = r8.g     // Catch:{ all -> 0x0078 }
            boolean r0 = r0.equals(r1)     // Catch:{ all -> 0x0078 }
            if (r0 != 0) goto L_0x0161
            com.flurry.sdk.ku$a r0 = com.flurry.sdk.ku.a.kPost     // Catch:{ all -> 0x0078 }
            com.flurry.sdk.ku$a r1 = r8.g     // Catch:{ all -> 0x0078 }
            boolean r0 = r0.equals(r1)     // Catch:{ all -> 0x0078 }
            if (r0 != 0) goto L_0x0161
            r8.j()
            goto L_0x0005
        L_0x0161:
            boolean r0 = r8.y     // Catch:{ all -> 0x0078 }
            if (r0 == 0) goto L_0x016a
            r8.j()
            goto L_0x0005
        L_0x016a:
            java.net.HttpURLConnection r0 = r8.d     // Catch:{ all -> 0x018f }
            java.io.InputStream r1 = r0.getInputStream()     // Catch:{ all -> 0x018f }
            java.io.BufferedInputStream r3 = new java.io.BufferedInputStream     // Catch:{ all -> 0x0198 }
            r3.<init>(r1)     // Catch:{ all -> 0x0198 }
            com.flurry.sdk.ku$c r0 = r8.k     // Catch:{ all -> 0x019d }
            if (r0 == 0) goto L_0x0184
            boolean r0 = r8.b()     // Catch:{ all -> 0x019d }
            if (r0 != 0) goto L_0x0184
            com.flurry.sdk.ku$c r0 = r8.k     // Catch:{ all -> 0x019d }
            r0.a(r8, r3)     // Catch:{ all -> 0x019d }
        L_0x0184:
            com.flurry.sdk.ly.a((java.io.Closeable) r3)     // Catch:{ all -> 0x0078 }
            com.flurry.sdk.ly.a((java.io.Closeable) r1)     // Catch:{ all -> 0x0078 }
            r8.j()
            goto L_0x0005
        L_0x018f:
            r0 = move-exception
            r1 = r2
        L_0x0191:
            com.flurry.sdk.ly.a((java.io.Closeable) r1)     // Catch:{ all -> 0x0078 }
            com.flurry.sdk.ly.a((java.io.Closeable) r2)     // Catch:{ all -> 0x0078 }
            throw r0     // Catch:{ all -> 0x0078 }
        L_0x0198:
            r0 = move-exception
            r7 = r1
            r1 = r2
            r2 = r7
            goto L_0x0191
        L_0x019d:
            r0 = move-exception
            r2 = r1
            r1 = r3
            goto L_0x0191
        L_0x01a1:
            r0 = move-exception
            r1 = r2
            r2 = r3
            goto L_0x0141
        L_0x01a5:
            r0 = move-exception
            r2 = r3
            goto L_0x0141
        */
        throw new UnsupportedOperationException("Method not decompiled: com.flurry.sdk.ku.i():void");
    }

    /* access modifiers changed from: package-private */
    public final void h() {
        if (this.k != null && !b()) {
            this.k.a(this);
        }
    }

    private void j() {
        if (!this.x) {
            this.x = true;
            if (this.d != null) {
                this.d.disconnect();
            }
        }
    }
}
